#!/bin/bash

## 获取网卡和IP
DEVICE=$(ip addr | egrep "mtu 1500 .* state UP" | awk -F ': ' '{print $2}' | head -n 1)
IPADDR=$(ip addr | egrep -w "inet.*$DEVICE" | awk '{print $2}' | awk -F '/' '{print $1}')


## 修改yaml的nfs地址和存储地址
sed -i "s#10.24.3.4#$IPADDR#g" nfs-client-storageclass.yaml
DIR="/data/kubernetes/storageclass/nfs-client-provisioner"
sed -i "s#/data/kubernetes/storageclass/nfs-client-provisioner#$DIR#g" nfs-client-storageclass.yaml

## 部署nfs-server服务
yum install -y nfs-utils rpcbind
echo "$DIR *(rw,async,no_root_squash)" >> /etc/exports
mkdir -p $DIR
#chmod a+w $DIR
systemctl restart nfs-server rpcbind
systemctl enable nfs-server rpcbind
showmount -e localhost

## 设置默认存储
# kubectl patch storageclass nfs-storageclass -p '{"metadata": {"annotations":{"storageclass.kubernetes.io/is-default-class":"true"}}}'
